package com.jbp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jbp.dao.PatchRecordDao;
import com.jbp.model.PatchRecord;
import com.jbp.service.PatchRecordService;
import org.springframework.stereotype.Service;
import com.jbp.utils.PageUtils;
import com.jbp.utils.Query;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 补贴记录(PatchRecord)表服务实现类
 * @author cc
 * @since 2020-08-05 01:24:30
 */
@Service
public class PatchRecordServiceImpl extends ServiceImpl<PatchRecordDao, PatchRecord> implements PatchRecordService {

    @Override
    public PatchRecord getByUserAndType(Integer userId, String poolType) {
        QueryWrapper<PatchRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("pool_type", poolType);
        PatchRecord patchRecord = getOne(queryWrapper);
        if (patchRecord==null) {
            patchRecord = new PatchRecord();
            patchRecord.setUserId(userId);
            patchRecord.setPoolType(poolType);
            patchRecord.setTimes(0);
            patchRecord.setIncome(BigDecimal.ZERO);
            patchRecord.setPay(BigDecimal.ZERO);
            patchRecord.setTotalPay(BigDecimal.ZERO);
            patchRecord.setTotalIncome(BigDecimal.ZERO);

            save(patchRecord);
        }
        return patchRecord;
    }
}